package com.wtpaint.leetcode.二叉树;

import java.util.ArrayList;
import java.util.List;

public class BinaryTreePaths {

    public List<String> binaryTreePaths(TreeNode root) {
        List<String> result = new ArrayList<>();

        if (null == root) {
            return null;
        }
        if (root.left == null && root.right == null) {
            result.add(root.val + "");
            return result;
        }

        List<String> left = binaryTreePaths(root.left);
        List<String> right = binaryTreePaths(root.right);

        for (String leftStr : left) {
            result.add(root.val + "->" + leftStr);
        }
        for (String rightStr : right) {
            result.add(root.val + "->" + rightStr);
        }

        return result;
    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }
}
